#include <bits/stdc++.h>
using namespace std;
int t,n,a[200005];
long long sum;
void ans(int x,int y)
{
    for(int i=x+1;i<=y;i++)
    {
        sum+=a[i];
        //cout<<a[i]<<"+";
    }
}
void ppt()
{
    cin>>n;
    sum=0;
    memset(a,0,sizeof(a));
    for(int i=1;i<=n;i++)
    {
        scanf("%d",&a[i]);
    }
    sort(a+1,a+n+1);
    //for(int i=1;i<=n;i++)
    //{
    //cout<<a[i]<<" ";
    //}
    //cout<<endl;
    int num=a[1],num1=1;
    for(int i=2;i<=n;i++)
    {
        if(a[i]!=num)
        {
            ans(num1,i-1);
            num1=i;
            num=a[i];
        }
    }
    ans(num1,n);
    cout<<sum<<endl;
}
int main()
{
    freopen("color.in","r",stdin);
    freopen("color.out","w",stdout);
    cin>>t;
    for(int i=1;i<=t;i++)
    {
        ppt();
    }
    return 0;
}
